<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1">
    <title id="bv20941">CREATE EXTENSION</title>
    <body>
        <p id="sql_command_desc">Registers an extension in a Greenplum database.</p>
        <section id="section2">
            <title>Synopsis</title>
            <codeblock id="sql_command_synopsis">CREATE EXTENSION [ IF NOT EXISTS ] <varname>extension_name</varname>
  [ WITH ] [ SCHEMA <varname>schema_name</varname> ]
           [ VERSION <varname>version</varname> ]
           [ FROM <varname>old_version</varname> ]
           [ CASCADE ]</codeblock>
        </section>
        <section id="section3">
            <title>Description</title>
            <p><codeph>CREATE EXTENSION</codeph> loads a new extension into the current database.
                There must not be an extension of the same name already loaded.</p>
            <p>Loading an extension essentially amounts to running the extension script file. The
                script typically creates new SQL objects such as functions, data types, operators
                and index support methods. The <codeph>CREATE EXTENSION</codeph> command also
                records the identities of all the created objects, so that they can be dropped again
                if <codeph>DROP EXTENSION</codeph> is issued.</p>
            <p>Loading an extension requires the same privileges that would be required to create
                the component extension objects. For most extensions this means superuser or
                database owner privileges are required. The user who runs <codeph>CREATE
                    EXTENSION</codeph> becomes the owner of the extension for purposes of later
                privilege checks, as well as the owner of any objects created by the extension
                script.</p>
        </section>
        <section id="section4">
            <title>Parameters</title>
            <parml>
                <plentry>
                    <pt>IF NOT EXISTS</pt>
                    <pd>
                        <p>Do not throw an error if an extension with the same name already exists.
                            A notice is issued in this case. There is no guarantee that the existing
                            extension is similar to the extension that would have been installed.
                        </p>
                    </pd>
                </plentry>
                <plentry>
                    <pt><varname>extension_name</varname></pt>
                    <pd>
                        <p>The name of the extension to be installed. The name must be unique within
                            the database. An extension is created from the details in the extension
                            control file
                                    <codeph><varname>SHAREDIR</varname>/extension/<varname>extension_name</varname>.control</codeph>. </p>
                        <p><varname>SHAREDIR</varname> is the installation shared-data directory,
                            for example <codeph>/usr/local/greenplum-db/share/postgresql</codeph>.
                            The command <codeph>pg_config --sharedir</codeph> displays the
                            directory.</p>
                    </pd>
                </plentry>
                <plentry>
                    <pt>SCHEMA <varname>schema_name</varname></pt>
                    <pd>
                        <p>The name of the schema in which to install the extension objects. This
                            assumes that the extension allows its contents to be relocated. The
                            named schema must already exist. If not specified, and the extension
                            control file does not specify a schema, the current default object
                            creation schema is used.</p>
                        <p>If the extension specifies a schema parameter in its control file, then
                            that schema cannot be overridden with a <codeph>SCHEMA</codeph> clause.
                            Normally, an error is raised if a <codeph>SCHEMA</codeph> clause is
                            given and it conflicts with the extension schema parameter. However, if
                            the <codeph>CASCADE</codeph> clause is also given, then
                                <varname>schema_name</varname> is ignored when it conflicts. The
                            given <varname>schema_name</varname> is used for the installation of any
                            needed extensions that do not a specify schema in their control
                            files.</p>
                        <p>The extension itself is not within any schema. Extensions have
                            unqualified names that must be unique within the database. But objects
                            belonging to the extension can be within a schema.</p>
                    </pd>
                </plentry>
                <plentry>
                    <pt>VERSION <varname>version</varname></pt>
                    <pd>
                        <p>The version of the extension to install. This can be written as either an
                            identifier or a string literal. The default version is value that is
                            specified in the extension control file.</p>
                    </pd>
                </plentry>
                <plentry>
                    <pt>FROM <varname>old_version</varname></pt>
                    <pd>
                        <p>Specify <codeph>FROM <varname>old_version</varname></codeph> only if you
                            are attempting to install an extension that replaces an <i>old-style</i>
                            module that is a collection of objects that is not packaged into an
                            extension. If specified, <codeph>CREATE EXTENSION</codeph> runs an
                            alternative installation script that absorbs the existing objects into
                            the extension, instead of creating new objects. Ensure that
                                <codeph>SCHEMA</codeph> clause specifies the schema containing these
                            pre-existing objects.</p>
                        <p>The value to use for <varname>old_version</varname> is determined by the
                            extension author, and might vary if there is more than one version of
                            the old-style module that can be upgraded into an extension. For the
                            standard additional modules supplied with pre-9.1 PostgreSQL, specify
                                <codeph>unpackaged</codeph> for the <varname>old_version</varname>
                            when updating a module to extension style.</p>
                    </pd>
                </plentry>
                <plentry>
                    <pt>CASCADE</pt>
                    <pd>
                        <p>Automatically install dependent extensions are not already installed.
                            Dependent extensions are checked recursively and those dependencies are
                            also installed automatically. If the <varname>SCHEMA</varname> clause is
                            specified, the schema applies to the extension and all dependent
                            extensions that are installed. Other options that are specified are not
                            applied to the automatically-installed dependent extensions. In
                            particular, default versions are always selected when installing
                            dependent extensions.</p>
                    </pd>
                </plentry>
            </parml>
        </section>
        <section id="section5">
            <title>Notes</title>
            <p>The extensions currently available for loading can be identified from the <i><xref
                        href="../system_catalogs/pg_available_extensions.xml#topic1"
                        >pg_available_extensions</xref></i> or <i><xref
                        href="../system_catalogs/pg_available_extension_versions.xml#topic_sln_wfx_tz"
                        >pg_available_extension_versions</xref></i> system views.</p>
            <p>Before you use <codeph>CREATE EXTENSION</codeph> to load an extension into a
                database, the supporting extension files must be installed including an extension
                control file and at least one least one SQL script file. The support files must be
                installed in the same location on all Greenplum Database hosts. For information
                about creating new extensions, see PostgreSQL information about <xref
                    href="https://www.postgresql.org/docs/9.6/extend-extensions.html"
                    format="html" scope="external">Packaging Related Objects into an
                    Extension</xref>.</p>
        </section>
        <section id="section7">
            <title>Compatibility</title>
            <p><codeph>CREATE EXTENSION</codeph> is a Greenplum Database extension. </p>
        </section>
        <section id="section8">
            <title>See Also</title>
            <p><codeph><xref href="ALTER_EXTENSION.xml#topic1">ALTER EXTENSION</xref></codeph>,
                        <codeph><xref href="DROP_EXTENSION.xml#topic1">DROP
                    EXTENSION</xref></codeph></p>
        </section>
    </body>
</topic>
